package cn.bdqn.controller;

import cn.bdqn.dto.Dto;
import cn.bdqn.util.VerificationToken;
import cn.bdqn.service.GuestService;
import cn.bdqn.vo.ItripUserLinkUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(description = "旅客信息相关")
@Controller
@RequestMapping("/api/userinfo")
public class GuestInfoController {

    @Resource
    private GuestService guestService;

//    /**
//     * 查询个人中心
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping(value = "/selectPersonalCenter",method = RequestMethod.POST,produces = "application/json")
//    @ApiOperation(value = "查询个人中心",httpMethod = "post",protocols = "HTTP",produces = "application/json",response = Dto.class)
//    public Dto selectPersonalCenter(@ApiParam(name = "userId",value = "用户平台Id[必给]",required = true) @RequestParam String userId,
//                                    @ApiParam(name = "currentPage",value = "当前页[选填]",required = false) @RequestParam String currentPage){
//
//
//        return guestService.selectGuestInfo(Long.parseLong(userId),currentPage);
//    }


    /**
     *旅客信息修改
     * @param itripUserLinkUserVO
     * @return
     */
    @ResponseBody
    @ApiOperation(value = "旅客信息修改",httpMethod = "post",protocols = "HTTP",produces = "application/json",response = Dto.class)
    @RequestMapping(value = "/modifyuserlinkuser",method = RequestMethod.POST,produces = "application/json")
    public Dto updateGuestInfo(@ApiParam (name = "itripUserLinkUserVO",value = "旅客信息修改实体")
                                @RequestBody ItripUserLinkUserVO itripUserLinkUserVO,
                                HttpServletRequest request){

        String[] userIds=request.getHeader("token").split("-");
        //token:PC-userCode-userID-date-random(6)
        Long userId=Long.parseLong(userIds[2]);
        boolean loginVerify=new VerificationToken().verification(request.getHeader("user-agent"),request.getHeader("token"));
        if (loginVerify){
            return guestService.updateGuestInfo(itripUserLinkUserVO,userId);
        }else {
            Dto dto=new Dto();
            dto.setCode("10086");
            dto.setSuccess("账号未登录");
           return dto;
        }
    }

    //旅客信息删除
    @ResponseBody
    @ApiOperation(value = "旅客信息删除",httpMethod = "get",protocols = "HTTP",produces = "application/json",response = Dto.class)
    @RequestMapping(value = "/deluserlinkuser",method = RequestMethod.GET,produces ="application/json" )
    public Dto delectGuest(@ApiParam(name = "ids",value = "旅客主键",required = true) @RequestParam String ids,
                           HttpServletRequest request){
        boolean loginVerify=new VerificationToken().verification(request.getHeader("user-agent"),request.getHeader("token"));
        if (loginVerify){
            return guestService.delectGuestInfo(Long.parseLong(ids));
        }else {
            Dto dto=new Dto();
            dto.setCode("10086");
            dto.setSuccess("账号未登录");
            return dto;
        }
    }


}
